var Reply = require("../../../class/_include/reply.c");
var User = require("../../../class/user/user.c");
var Module = require("../../../class/user/module.c");
var Post = require("../../../class/user/post.c");
var _Reply = new Reply();
var _User = new User();
var _Module = new Module();
var _Post = new Post();
module.exports = {
    prefix: "/user/reply/",
    get: {
        "list": {
            des: {
                name: "getUserReplyList",
                content: "获取用户回复列表",
                params: [
                    {
                        key: "creater_id",
                        type: "string",
                    },
                    {
                        key: "replyer_id",
                        type: "string"
                    },
                    {
                        key: "page",
                        type: "Number"
                    },
                    {
                        key: "num",
                        type: "Number"
                    }
                ]
            },
            method: function* () {
                var self = this;
                print("正在获取用户回复列表");
                try {
                    var data = self.request.query;
                    var _list = yield _Reply.list(data);
                    self.body = _list;
                } catch (e) {
                    self.body = printError(e);
                };
            }
        },
        "count": {
            des: {
                name: "getUserReplyCount",
                content: "获取用户回复统计",
                params: [
                    {
                        key: "creater_id",
                        type: "string"
                    },
                    {
                        key: "replyer_id",
                        type: "string"
                    }
                ]
            },
            method: function* () {
                var self = this;
                print("正在获取用户回复统计");
                try {
                    var data = self.request.query;
                    var _count = yield _Reply.count(data);
                    self.body = _count;
                } catch (e) {
                    self.body = printError(e);
                };
            }
        }
    },
    delete: {
        "delete/:_id": {
            des: {
                name: "deleteReplyById",
                content: "根据_id删除对应回复",
                params: [
                    {
                        params: "_id",
                        type: "string"
                    }
                ]
            },
            method: function* () {
                var self = this;
                print("正在删除用户回复");
                try {
                    var _id = self.params._id;
                    var _r = yield _Reply.delete(_id);
                    self.body = (_r);
                    if ((_r.type !== "error") && self.session.user) {
                        // 删除一条回复的时候，涉及到的版块回复数-1
                        yield _Module.upgradereply(_r._module);
                        // 涉及到的话题回复数-1
                        yield _Post.upgradereply(_r.post_id);
                        // 回复用户的回复数-1
                        var _u = yield _User.upgradereply(self.session.user._id);
                        _u.info = self.session.user.info
                        self.session.user = _u;
                    };
                } catch (e) {
                    self.body = printError(e);
                };
            }
        }
    }
}